#pragma once

#include <QtCore/QJsonArray>
#include <QtCore/QJsonObject>
#include <QtCore/QMap>
#include <QtCore/QString>

namespace qtc_alarm_core {

struct AlarmTableRow {
    QString pv;
    QString severity;
    QString message;
    QString value;
    qint64  time_epoch_ms {0};
    bool acknowledged {false};

    QJsonObject toJson() const {
        QJsonObject o;
        o["pv"] = pv;
        o["severity"] = severity;
        o["message"] = message;
        o["value"] = value;
        o["time_epoch_ms"] = static_cast<double>(time_epoch_ms);
        o["acknowledged"] = acknowledged;
        return o;
    }
};

class AlarmTable {
public:
    void applyStateJson(const QString& pv, const QJsonObject& obj);
    QJsonArray toJsonArray() const;

private:
    QMap<QString, AlarmTableRow> rows;
};

} // namespace qtc_alarm_core